import request from '@/utils/request'

export function getList(type, params) {
  let url = ''
  switch (type) {
    case 'getClip':
      url = 'getClip'
      break
    case 'getClipOrder':
      url = 'getClipOrder'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'get',
      params
    })
      .then(res => {
        resolve(res)
      })
      // eslint-disable-next-line handle-callback-err
      .catch(error => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve(data)
      })
  })
}

export function addOne(type, data) {
  let url = ''
  switch (type) {
    case 'getClipAdd':
      url = 'getClipAdd'
      break
    case 'getClipAddList':
      url = 'getClipAddList'
      break
    case 'getClipOrderAdd':
      url = 'getClipOrderAdd'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function updateOne(type, data) {
  let url = ''
  switch (type) {
    case 'getClipUpdate':
      url = 'getClipUpdate'
      break
    case 'getClipCheck':
      url = 'getClipCheck'
      break
    case 'getClipBatchUpdate':
      url = 'getClipBatchUpdate'
      break
    case 'getClipOrderUpdate':
      url = 'getClipOrderUpdate'
      break
    case 'getClipOrderCheck':
      url = 'getClipOrderCheck'
      break
    case 'getClipOrderBatchUpdate':
      url = 'getClipOrderBatchUpdate'
      break
    case 'getCilpSync':
      url = 'getCilpSync'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}

export function deleteOne(type, data) {
  let url = ''
  switch (type) {
    case 'getClipDelete':
      url = 'getClipDelete'
      break
    case 'getClipOrderDelete':
      url = 'getClipOrderDelete'
      break
    default:
      break
  }
  return new Promise((resolve, reject) => {
    request({
      url,
      method: 'post',
      data
    })
      .then(res => {
        resolve(res)
      })
      .catch(() => {
        const data = {
          total: 0,
          pageItems: []
        }
        resolve({ data })
      })
  })
}
